package com.rexolar.openapi.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Description 拦截器注册
 * @Author  zhusiyu
 * @Date 2024/09/18
 * @Version 1.0
 */
@Configuration
public class RegistryInterceptor implements WebMvcConfigurer {

    @Autowired
    private AuthInterceptor authInterceptor;
    @Autowired
    private SignInterceptor signInterceptor;
    @Autowired
    private PublicParamsCheckInterceptor publicParamsCheckInterceptor;
    @Autowired
    private ReqParamsInterceptor reqParamsInterceptor;

    /**
     * 注册用户认证拦截器，配置放行请求
     *
     * @param registry 注册对象
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration interceptorRegistration = registry.addInterceptor(reqParamsInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(//添加不拦截路径
                        "/login",            //登录
                        "/xsse",            //登录
                        "/rexolar/openapi/xsse",            //登录
                        "/refreshToken",            //刷新Token
                        "/file/upload",            //上传文件
                        "/file/download/**",            //下载文件
                        "/monitor/**",            //
                        "/dataV/**",            //数据大屏接口
                        "/error/**",            //错误信息
                        "/**/*.html",            //html静态资源
                        "/**/*.js",              //js静态资源
                        "/**/*.css",             //css静态资源
                        "/**/*.png",             //css静态资源
                        "/**/*.jpg",             //css静态资源
                        "/**/*.woff",
                        "/**/*.woff2",
                        "/**/*.gif",
                        "/**/*.eot",
                        "/**/*.svg",
                        "/**/*.ttf");

        registry.addInterceptor(publicParamsCheckInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(//添加不拦截路径
                        "/login",            //登录
                        "/xsse",            //登录
                        "/rexolar/openapi/xsse",            //登录
                        "/refreshToken",            //刷新Token
                        "/file/upload",            //上传文件
                        "/file/download/**",            //下载文件
                        "/monitor/**",            //
                        "/dataV/**",            //数据大屏接口
                        "/error/**",            //错误信息
                        "/**/*.html",            //html静态资源
                        "/**/*.js",              //js静态资源
                        "/**/*.css",             //css静态资源
                        "/**/*.png",             //css静态资源
                        "/**/*.jpg",             //css静态资源
                        "/**/*.woff",
                        "/**/*.woff2",
                        "/**/*.gif",
                        "/**/*.eot",
                        "/**/*.svg",
                        "/**/*.ttf");
        registry.addInterceptor(signInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(//添加不拦截路径
                        "/login",            //登录
                        "/xsse",            //登录
                        "/rexolar/openapi/xsse",            //登录
                        "/refreshToken",            //刷新Token
                        "/file/upload",            //上传文件
                        "/file/download/**",            //下载文件
                        "/monitor/**",            //
                        "/dataV/**",            //数据大屏接口
                        "/error/**",            //错误信息
                        "/**/*.html",            //html静态资源
                        "/**/*.js",              //js静态资源
                        "/**/*.css",             //css静态资源
                        "/**/*.png",             //css静态资源
                        "/**/*.jpg",             //css静态资源
                        "/**/*.woff",
                        "/**/*.woff2",
                        "/**/*.gif",
                        "/**/*.eot",
                        "/**/*.svg",
                        "/**/*.ttf");
        registry.addInterceptor(authInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(//添加不拦截路径
                        "/login",            //登录
                        "/xsse",            //登录
                        "/rexolar/openapi/xsse",            //登录
                        "/refreshToken",            //刷新Token
                        "/file/upload",            //上传文件
                        "/file/download/**",            //下载文件
                        "/monitor/**",            //
                        "/dataV/**",            //数据大屏接口
                        "/error/**",            //错误信息
                        "/**/*.html",            //html静态资源
                        "/**/*.js",              //js静态资源
                        "/**/*.css",             //css静态资源
                        "/**/*.png",             //css静态资源
                        "/**/*.jpg",             //css静态资源
                        "/**/*.woff",
                        "/**/*.woff2",
                        "/**/*.gif",
                        "/**/*.eot",
                        "/**/*.svg",
                        "/**/*.ttf");

    }
}
